<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <link href="asserts/plugins/bootstrap/css/bootstrap.css" rel="stylesheet">
    <script src="asserts/plugins/jquery-3.6.0.min.js"></script>
    <script src="asserts/plugins/bootstrap/js/bootstrap.js"></script>

    <script>
        $(function () {
            // 用户登录
            $("button[id=login]").click(function () {
                //先判断验证码
                $.ajax({
                    url: "/KunKunMarket/CheckController",
                    type:"get",
                    dataType: "json",
                    data:{
                        type:'checkCode',
                        code: $("#code_text").val()
                    },
                    success: function (respBean) {
                        console.log(respBean.msg);
                        if (respBean.status == 500){
                            alert("验证码错误");
                        }else {
                            let username = $("input[name=username]").val();
                            let password = $("input[name=password]").val();
                            $.ajax({
                                url:"/KunKunMarket/UserController?type=login&username=" + username + "&password=" + password,
                                type:"get",
                                dataType:"json",
                                success:function (respBean) {
                                    alert(respBean.msg);
                                    if (respBean.status == 200){
                                        location.href = "commodity/commodityList.html"
                                    }
                                }
                            })
                        }
                    }
                })


            })
            // 管理员登录
            $("button[id=loginAdmin]").click(function () {

                let username = $("input[name=username]").val();
                let password = $("input[name=password]").val();
                $.ajax({
                    url:"/KunKunMarket/AdminController?type=login&name=" + username + "&password=" + password,
                    type:"get",
                    dataType:"json",
                    success:function (respBean) {
                        alert(respBean.msg);
                        if (respBean.status == 200){
                            location.href = "admin/adminIndex.html";
                        }
                    }
                })

            })
        })
    </script>
</head>
<body>
<h1 style="text-align: center">登录</h1>

    <div class="container">
        <form>
            <div class="form-group">
                <label for="exampleInputEmail1">账号</label>
                <input type="text" name="username" class="form-control input-lg" id="exampleInputEmail1" placeholder="请输入账号">
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">密码</label>
                <input type="password" name="password" class="form-control input-lg" id="exampleInputPassword1" placeholder="请输入密码">
            </div>
            <div class="form-group">
                <img src="/KunKunMarket/CheckController?type=getCode" id="code_img">
                <input type="text" name="code" class="form-control input-lg" id="code_text" placeholder="请输入验证码">
            </div>
            <button type="button" id="login" class="btn btn-default">登录</button>
            <button type="button" id="loginAdmin" class="btn btn-default">管理员登录</button>
        </form>
    </div>






</body>
</html>